<?php

/**
 * Created by PhpStorm.
 * User: Apache
 *   官网的相关接口
 *
 */

namespace app\api\controller\basemanage;

use think\Db;
use think\Model;
use app\api\model\Admin as AdminModel;
use app\api\controller\common\CommonPlus;
use think\Controller; // dengh quxiao
// Controller  ApiBase （dengl）
class Webbusinessman extends Controller
{

    protected $admin;
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->admin = session('admin');
    }


    //根据展会id查询动态展商表
    public function getTabName($exhibition_id)
    {
        $result = db('exhibition')->where(['id' => $exhibition_id])->find();
        $tabName = "";
        if ($result) {
            $tabName = $result['create_tablename'];
        } else {
            return json(['code' => 0, 'msg' => '缺少关键字段', 'data' => '']);
        }
        return $tabName;
    }

    //展商登录
    public function login_zs()
    {

        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $account = $this->request->param('account'); //账号
        $pwd = $this->request->param('pwd'); //密码
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }

        if ($exhibition['login_strat_time'] > time()) {
            return json(['code' => 0, 'msg' => '展会信息登记还未开始']);
        }
        if ($exhibition['login_end_time'] < time()) {
            return json(['code' => 0, 'msg' => '展会信息登记已经结束']);
        }
        $tabName = $this->getTabName($exhibition_id);
        $res = db($tabName)->where(['account' => $account])->find();
//        var_dump($res);die();
        if (!$res) {
            return json(['code' => 0, 'msg' => '登录账号错误']);
        }

        //判断密码
        if ($pwd != $res['pwd']) {
            return json(['code' => 0, 'msg' => '登录密码错误']);
        }
        //成功之后返回展商id
        return json(['code' => 1, 'msg' => '登录成功', 'data' => $res['id']]);
    }

    //展商密码修改 35 7 112233 
    public function login_zs_pwd_reset()
    {
        $com=new CommonPlus();

        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $id_zs = $this->request->param('id_zs'); //展商id
        $account = $this->request->param('account'); //账号
        $pwd = $this->request->param('pwd'); //密码
        $pwd_before = $this->request->param('pwd_before'); //密码
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
         
        if (empty($pwd)) {
            return json(['code' => 0, 'msg' => '请输入密码']);
        }


        $tabName = $this->getTabName($exhibition_id); // cerar
        // 查用户名有点不妥 ,先按照展商id 密码差
        //$res = db($tabName)->where(['account' => $account])->find();
    
        $where['id'] = $id_zs;         
       // $where['pwd'] = md5(md5($pwd_before)); // 形同虚设 很多会忘记密码
        $res=$com->sel_com_one('222', $where, $tabName);


       // $res = db($tabName)->where(['id' => $id_zs])->find();
        if (!$res) {
            return json(['code' => 0, 'msg' => '未查询到相关用户']);
        }

        
        // 修改密码
        $where1['id'] = $id_zs;
        $data['pwd']=$pwd;
        $res=$com->edit_com_fxlist($data, $where1, $tabName);
        if (!$res) {
            return json(['code' => 0, 'msg' => '修改失败']);
        }

        //成功之后返回展商id
        return json(['code' => 1, 'msg' => '修改成功', 'data' => $res['id']]);
    }


    //获取展商详情
    public function getBusDetail()
    {
//        return json(['code' => 1, 'msg' => '查询成功', 'data' => '']);
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $id = $this->request->param('id'); //展商id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        $business = db($tabName)->where(['id' => $id])->find();// 展商表
        // var_dump(unserialize($business['doselfbrander_info']));die;
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }else{
            $business['country_chukou']=unserialize($business['country_chukou']);
            $business['doselfbrander_info']=unserialize($business['doselfbrander_info']); 
        }
        $sql="SELECT b.number,h.title as hall_title FROM crm_booth AS b ";
        $sql.=" LEFT JOIN crm_hall as h ON h.id=b.hall_id AND h.is_delete=0";
        $sql.=" WHERE b.id in(select id_zwei from crm_contract where is_delete=0 and id_zs=".$id." and id_zhui=".$exhibition_id.") AND b.is_delete=0 ";
        $boothList=Db::query($sql);
        foreach ($boothList as $k => &$v) {
            $v['number']=$v['hall_title']."-".$v['number'];
        }
        $storage='';
        $business['both'] = $boothList;//implode('、', $boothRes);
        $storage=db('company_storage')->where(['company_id'=>$id,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
        $association_member=db('company_label')->where(['company_id'=>$business['company_id1'],'label'=>'协会展商'])->find();
        $business['association_member']=$association_member?1:0;
        $business['second_category_id']=empty($business['second_category_id'])?null:$business['second_category_id'];
        //成功之后返回展商数据
        return json(['code' => 1, 'msg' => '查询成功', 'data' => $business,'storage'=>$storage]);
    }

    //获取领时数据
    public function getEnterStorage(){
        $id = $this->request->param('id'); //展商id
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        $business = db($tabName)->where(['id' => $id])->find();// 展商表
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }
        $storage=db('company_storage')->where(['company_id'=>$id,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
        return json(['code' => 1, 'msg' => '操作成功','data'=>$storage['enter_storage'],'goods'=>$storage['goods_storage'],'id'=>$storage['id']]);
    }
    //保存临时数据
    public function enterStorage(){
        $id = $this->request->param('id'); //展商id
        $enter_storage = $this->request->param('enter_storage'); //展商id
        $goods_storage = $this->request->param('goods_storage'); //展商id
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        $business = db($tabName)->where(['id' => $id])->find();// 展商表
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }


        $data['company_id']=$id;
        if($enter_storage){
            $data['enter_storage']=$enter_storage;
        }
        if($goods_storage){
            $data['goods_storage']=$goods_storage;
        }
        $data['exhibition_id']=$exhibition_id;
        $res='';
        $storageId='';
        $storage=db('company_storage')->where(['company_id'=>$id,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
        if($storage){
            $res=db('company_storage')->where(['id'=>$storage['id']])->update($data);
            $storageId=$storage['id'];
        }else{
            $data['create_time']=time();
            $res=db('company_storage')->insertGetId($data);
            $storageId=$res;
        }
        if(!$res){
            return json(['code' => 0, 'msg' => '操作失败']);
        }
        return json(['code' => 1, 'msg' => '操作成功','data'=>$storageId]);
    }

    public function delEnterStorage(){
        return json(['code' => 1, 'msg' => '操作成功']);
//        $id = $this->request->param('id'); //展商id
//        $storage=db('company_storage')->where(['id'=>$id])->find();
//        if(!$storage){
//            return json(['code' => 1, 'msg' => '缓存信息错误']);
//        }
//        $res=db('company_storage')->delete($id);
//        if (!$res) {
//            return json(['code' => 1, 'msg' => '展商数据错误']);
//        }
//        return json(['code' => 1, 'msg' => '操作成功']);
    }

    //获得胸牌数量
    public function getXpNumber(){
        $id = $this->request->param('id'); //展商id
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        $business = db($tabName)->where(['id' => $id])->find();// 展商表
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }
        //c.id_zs,c.id_zwei,c.id_zhui
        $sql="select * from crm_booth where id in (select id_zwei from crm_contract where id_zhui=".$exhibition_id." and is_delete=0 and id_zs=".$id.")";
        $both = Db::query($sql);
        $numList = db('both_type')->where(['type' => 1])->select();
        $addNum=is_numeric($business['label_2'])?$business['label_2']:0;
        $xkNum=0;
        foreach ($both as $key => &$v) {
            $v['xkNum']=4;
            foreach ($numList as $k => &$vv) {
                if($v['area'] == $vv['title']){
                    $v['xkNum']=$vv['number'];
                }
            }
            $xkNum+=$v['xkNum'];
        }
        $xkNum=$xkNum+$addNum;
        return json(['code' => 1, 'msg' => '查询成功', 'data' => $both,'xkNum'=>$xkNum]);
    }

    // 参展历史记录
    public function getHisroy()
    {
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $id = $this->request->param('id'); //展商id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 0, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);

        //查询展商信息
        $business = db($tabName)->where(['id' => $id])->find();
        if (!$business) {
            return json(['code' => 0, 'msg' => '展商数据错误']);
        }
        $result = db('exhibition')->where(['is_delete' => 0])->select();
        $association_member=db('company_label')->where(['company_id'=>$business['company_id1'],'label'=>'协会展商'])->find();
        $histroyList = array();
        foreach ($result as $key => &$v) {
            $createTab = $v['create_tablename'];
            $w['company_id1'] = $business['company_id1'];
            $w['status'] = ['egt', 4];
            $company_public =  db($createTab)->where($w)->find();
            if (!empty($company_public)) {
                $data['id'] = $company_public['id'];
                $data['title'] = $v['title'];
                $data['exhibition_id'] = $v['id'];
                $data['company_name'] = $company_public['company_name'];
                $data['association_member']=$association_member?1:0;
                $histroyList[]=$data;
            }
        }

        return json(['code' => 1, 'msg' => 'success', 'data' => $histroyList]);
    }

    //会刊录入单个
    public function editOneCompany(){
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $id = $this->request->param('id'); //展商id
        $jsonName = $this->request->param('jsonName'); //字段名
        $value = $this->request->param('value'); //字段值
        if(empty($jsonName) || $value==''){
            return json(['code' => 0, 'msg' => '数据错误']);
        }
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 0, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        //查询展商信息
        $business = db($tabName)->where(['id' => $id])->find();
        if (!$business) {
            return json(['code' => 0, 'msg' => '展商数据错误']);
        }
        if($jsonName=='cityJsons'){
            $address = explode(",", $value);
            if(count($address)!=4){
                return json(['code' => 0, 'msg' => '失败']);
            }
            $res=db($tabName)->where(['id'=>$id])->update(['province'=>$address[0],'area_city'=>$address[1],'area_town'=>$address[2],'area'=>$address[3]]);
        }else{
            if($jsonName=='doselfbrander_info' || $jsonName=='country_chukou'){
                $value = serialize(json_decode($value, TRUE)); // 序列
            }
            $res=db($tabName)->where(['id'=>$id])->update([$jsonName=>$value]);
        }

        if(!$res){
            return json(['code' => 0, 'msg' => '失败']);
        }
        return json(['code' => 1, 'msg' => '成功']);
    }
    /**
     * @return \think\response\Json
     *  会刊录入========
     *   根据公司id 这个是展商表还是基础库呢
     *   
     *  根据下拉框。获取展商id  展会exhibiton id 是一直有
     * 35   展会id 8777
     */
    public function editCompany()
    {
        $com = new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id'); //展会id
        $id = $this->request->param('id'); //展商id
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 0, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        //查询展商信息
        $business = db($tabName)->where(['id' => $id])->find();
        if (!$business) {
            return json(['code' => 0, 'msg' => '展商数据错误']);
        }

        $where['id'] = $exhibition_id;
        $tbname = "exhibition";
        $info_zh = $com->sel_com_one('222', $where, $tbname); // 查展会
        
        $where1['id'] = $id; // 展商id
        $info_zs = $com->sel_com_one('222', $where1, $info_zh['create_tablename']); // 查展商
        // 
        if (!$info_zs) {
            return json(['code' => 0, 'msg' => '未查询到相关展商信息']);
        }

        $data = array();

        $logo = $this->request->param('logo');  //  logo 
        if (!empty($logo)) {
            $data['logo'] = $logo;
        }

        $info_card_logo = $this->request->param('info_card_logo');  //  logo
        if (!empty($info_card_logo)) {
            $data['info_card_logo'] = $info_card_logo;
        }

        $Issue_on_behalf = $this->request->param('Issue_on_behalf');  //  一件代发
        if (!empty($info_card_logo)) {
            $data['Issue_on_behalf'] = $Issue_on_behalf;
        }

        $edit_logo = $this->request->param('edit_logo');  //  可编辑logo
        if (!empty($edit_logo)) {
            $data['edit_logo'] = $edit_logo;
        }

//        $company_name = $this->request->param('company_name'); //公司中文名
//        if (!empty($company_name)) {
//            $data['company_name'] = $company_name;
//        }
        $company_name_en = $this->request->param('company_name_en'); //    公司英文文名
        if (!empty($company_name_en)) {
            $data['company_name_en'] = $company_name_en;
        }

        $quality_system = $this->request->param('quality_system'); // 证书信息
        $data['quality_system'] = $quality_system?$quality_system:0;

        $quality_system_zheng = $this->request->param('quality_system_zheng'); //简介  中文
        if (!empty($quality_system_zheng)) {
            $data['quality_system_zheng'] = $quality_system_zheng;
        }

        $company_describe = $this->request->param('company_describe'); //简介  中文 
        if (!empty($company_describe)) {
            $data['company_describe'] = $company_describe;
        }
        $company_describe_en = $this->request->param('company_describe_en'); //公司简介英文 
        if (!empty($company_describe_en)) {
            $data['company_describe_en'] = $company_describe_en;
        }
        $category_id = $this->request->param('category_id');  //一级 分类
        if (!empty($category_id)) {
            $data['category_id'] = $category_id;
        }
        $second_category_id = $this->request->param('second_category_id');     //二级 分类
        if (!empty($second_category_id)) {
//            $data['second_category_id'] = $second_category_id;
        }
//        var_dump($data['second_category_id']);die();
        $product = $this->request->param('product');  //产品
        if (!empty($product)) {
            $data['product'] = $product;
        }
        $product_describe = $this->request->param('product_describe');   //产品介绍
        if (!empty($product_describe)) {
            $data['product_describe'] = $product_describe;
        }
        $product_describe_cn = $this->request->param('product_describe_cn');   //产品介绍英文
        if (!empty($product_describe_cn)) {
            $data['product_describe_cn'] = $product_describe_cn;
        }
        //
        $isdoselfbrander = $this->request->param('isdoselfbrander') == "" ? 0 : $this->request->param('isdoselfbrander'); // 是否做过自由品牌
        $data['isdoselfbrander'] = $isdoselfbrander;

        $doselfbrander_info = $this->request->param('doselfbrander_info'); // 自由品牌信息       
        $doselfbrander_info = serialize(json_decode($doselfbrander_info, TRUE)); // 序列 
        if (!empty($doselfbrander_info)) {
            $data['doselfbrander_info'] = $doselfbrander_info;
        }

        $is_chukou = $this->request->param('is_chukou') == "" ? 0 : $this->request->param('is_chukou');  // 是否出口
        $data['is_chukou'] = $is_chukou;

        $country_chukou = $this->request->param('country_chukou');  // 出口国家
        $country_chukou = serialize(json_decode($country_chukou, TRUE)); // 序列
        if (!empty($country_chukou)) {
            $data['country_chukou'] = $country_chukou;
        }

        $is_card_sheng = $this->request->param('is_card_sheng') == "" ? 0 : $this->request->param('is_card_sheng');  //  是否获取省级证书  的
        $data['is_card_sheng'] = $is_card_sheng;

        $info_card_sheng = $this->request->param('info_card_sheng'); // 证书信息
        if (!empty($info_card_sheng)) {
            $data['info_card_sheng'] = $info_card_sheng;
        }

        // ---
        $country = $this->request->param('country');  //国家
        if (!empty($country)) {
            $data['country'] = $country;
        }

        //$country_code = $this->request->param('country_code'); //国家代码
        $province = $this->request->param('province');  //省份
        if (!empty($province)) {
            $data['province'] = $province;
        }
        $area_city = $this->request->param('area_city');  //地级市  
        if (!empty($area_city)) {
            $data['area_city'] = $area_city;
        }
        $area_town = $this->request->param('area_town'); //县市
        if (!empty($area_town)) {
            $data['area_town'] = $area_town;
        }
        $area = $this->request->param('area'); //区域
        if (!empty($area)) {
            $data['area'] = $area;
        }

        $company_address = $this->request->param('company_address'); //地址
        if (!empty($company_address)) {
            $data['company_address'] = $company_address;
        }

        $company_address_en = $this->request->param('company_address_en'); //地址英文 
        if (!empty($company_address_en)) {
            $data['company_address_en'] = $company_address_en;
        }


        $name_cn = $this->request->param('name_cn');     // 中文名
        if (!empty($name_cn)) {
            $data['name_cn'] = $name_cn;
        }

        $name_en = $this->request->param('name_en'); // 英文名
        if (!empty($name_en)) {
            $data['name_en'] = $name_en;
        }

        $mobile = $this->request->param('mobile');
        if (!empty($mobile)) {
            $data['mobile'] = $mobile;
        }

        $tel = $this->request->param('tel');   //固定电话 拼接带区号
        if (!empty($tel)) {
            $data['tel'] = $tel;
        }

        $fax_person = $this->request->param('fax_person');  // 传真
        if (!empty($fax_person)) {
            $data['fax_person'] = $fax_person;
        }

        $email = $this->request->param('email'); //邮件
        if (!empty($email)) {
            $data['email'] = $email;
        }

        $link = $this->request->param('link'); // 网址
        if (!empty($link)) {
            $data['link'] = $link;
        }

        $data['update_time']=time();
        $data['label']=1;
        $where1['id'] = $id; // 展商id
        $up_zs = $com->edit_com_fxlist($data, $where1, $info_zh['create_tablename']); // 先查展会里展商  查展商


        if (!$up_zs) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        //是否协会会员
        $association_member=$this->request->param('association_member');
        if($association_member == 1){
            $association_res=db('company_label')->where(['company_id'=>$business['company_id1'],'label'=>'协会展商'])->find();
            if(!$association_res){
                $associationData['update_time']=time();
                $associationData['label']='协会展商';
                $associationData['company_id']=$id;
                $associationData['label_type']=2;
                $associationData['create_time']=date('Y');
                db('company_label')->insert($associationData);
            }
        }


        //删除缓存数据
        db('company_storage')->where(['exhibition_id'=>$exhibition_id,'company_id'=>$id,'is_delete'=>0])->update(['is_delete'=>1]);

        // 更新基础库===============
        $where2 = array('id' => $info_zs['company_id1']);
        $tbname = 'company';
        $info_comp = $com->sel_com_one('2', $where2, $tbname);
        if ($info_comp) {
            // 有些缺字段 局部更新基础库
            $data = array();

            $logo = $this->request->param('logo');  //  logo 
            if (!empty($logo)) {
                $data['logo'] = $logo;
            }
//            $company_name = $this->request->param('company_name'); //公司中文名
//            if (!empty($company_name)) {
//                $data['company_name'] = $company_name;
//            }
            $company_name_en = $this->request->param('company_name_en'); //    公司英文文名
            if (!empty($company_name_en)) {
                $data['company_name_en'] = $company_name_en;
            }
            $company_describe = $this->request->param('company_describe'); //简介  中文 
            if (!empty($company_describe)) {
                $data['company_describe'] = $company_describe;
            }
            $company_describe_en = $this->request->param('company_describe_en'); //公司简介英文 
            if (!empty($company_describe_en)) {
                //$data['company_describe_en']=$company_describe_en; // 缺字段
            }
            $category_id = $this->request->param('category_id');  //一级 分类
            if (!empty($category_id)) {
                $data['category_id'] = $category_id;
            }
            $second_category_id = $this->request->param('second_category_id');     //二级 分类
            if (!empty($second_category_id)) {
                $data['second_category_id'] = $second_category_id;
            }
            $product = $this->request->param('product');  //产品
            if (!empty($product)) {
                $data['product'] = $product;
            }
            $product_describe = $this->request->param('product_describe');   //产品介绍
            if (!empty($product_describe)) {
                $data['product_describe'] = $product_describe;
            }
            $product_describe_cn = $this->request->param('product_describe_cn');   //产品介绍英文
            if (!empty($product_describe_cn)) {
                //$data['product_describe_cn']=$product_describe_cn;
            }


            // ---
            $country = $this->request->param('country');  //国家
            if (!empty($country)) {
                $data['country'] = $country;
            }

            //$country_code = $this->request->param('country_code'); //国家代码
            $province = $this->request->param('province');  //省份
            if (!empty($province)) {
                $data['province'] = $province;
            }
            $area_city = $this->request->param('area_city');  //地级市
            if (!empty($area_city)) {
                $data['area_city'] = $area_city;
            }
            $area_town = $this->request->param('area_town'); //县市
            if (!empty($area_town)) {
                $data['area_town'] = $area_town;
            }
            $area = $this->request->param('area'); //区域
            if (!empty($area)) {
                $data['area'] = $area;
            }

            $company_address = $this->request->param('company_address'); //地址
            if (!empty($company_address)) {
                $data['company_address'] = $company_address;
            }

            $company_address_en = $this->request->param('company_address_en'); //地址英文 
            if (!empty($company_address_en)) {
                //$data['company_address_en']=$company_address_en;
            }


            $name_cn = $this->request->param('name_cn');     // 中文名
            if (!empty($name_cn)) {
                $data['name_cn'] = $name_cn;
            }

            $name_en = $this->request->param('name_en'); // 英文名
            if (!empty($name_en)) {
                $data['name_en'] = $name_en;
            }

            $mobile = $this->request->param('mobile');
            if (!empty($mobile)) {
                $data['mobile'] = $mobile;
            }

            $tel = $this->request->param('tel');   //固定电话 拼接带区号
            if (!empty($tel)) {
                $data['tel'] = $tel;
            }

            $fax_person = $this->request->param('fax_person');  // 传真
            if (!empty($fax_person)) {
                $data['fax_person'] = $fax_person;
            }

            $email = $this->request->param('email'); //邮件
            if (!empty($email)) {
                $data['email'] = $email;
            }

            $link = $this->request->param('link'); // 网址
            if (!empty($link)) {
                $data['link'] = $link;
            }

            $up_comp = $com->edit_com_fxlist($data, $where2, $tbname); // 先查展会里展商  查展商   
        }

        return json(['code' => 1, 'msg' => '操作成功']);
    }

    // 展品相关关============
    // 展品列表 
    public function zp_getList()
    {
        $com=new CommonPlus();
        $page = $this->request->param('page');
        $page = max(1, intval($page));
        $pagesize = $this->request->param('pageSize') == "" ? 20 : $this->request->param('pageSize');
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('id_zs');
        $status = $this->request->param('status') == '' ? 1 : $this->request->param('status');
        if (empty($exhibition_id)) {
            return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }

        $status = input('status');
        //back字段 0代表正常 1代表退回数据 2 代表自提 3代表分配
        //status前端传入1代表 全部 2代表 不展示退回数据 3代表 只展示退回数据
        $param=" and is_del=0";
        if($exhibition_id){
            $param .= " and exhibition_id=".$exhibition_id;
        }
        if($id_zs){
            $param .= " and id_zs=".$id_zs;
        }



        $keyword = input('keyword');
        if (!empty($keyword)) {
            $param .= " and (title like '%$keyword%' or title_en like '%$keyword%') ";
        }
        $sql2 = "select * ";
        $sql2 .= " from crm_zsgoodszp where 1=1 $param";
        $sql2 .= " limit " . ($page - 1) * $pagesize . ",$pagesize";
        //var_dump($sql2);die();
        $list = Db::query($sql2);

        $sql21 = " select count(id) as count1 ";
        $sql21 .= " from crm_zsgoodszp where 1=1 $param ";
        $total1 = Db::query($sql21);
        $total = $total1[0]['count1']; //st
        // 1
        if(!$list){
            return json(['code'=>1,'msg'=>'未查询到相关信息','data'=>[]]);
        }
        foreach ($list as &$val) {
            $val['product'] = $val['title'];
            $val['is_news'] = $val['is_news'];
            $val['index'] = $val['index'];
            $val['product_describe_cn'] = $val['intro'];
            $val['product_describe'] = $val['intro_en'];
            $val['product_pic'] = $val['pic']?unserialize($val['pic']):[];
            $val['category'] = $val['category']?unserialize($val['category']):[];
        }
        unset($val);
        return json(['code' => 1, 'msg' => 'success', 'data' => ['list' => $list, 'count' => $total]]);
    }


    /**
     *  数组形式
     *      * (json_decode(htmlspecialchars_decode($_GPC['datas']),true));die();
     *   // 1.2 版本 有些东西是下拉选择
     *  "[{"id":"16","title":"无缝钢管","pid":"5","guige":"D22","num":"11"}]"  ke ce
     */
    public function zp_add()
    {
        $com = new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('id_zs'); // 展商
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }
        $data['create_time'] = time();
        $data['exhibition_id'] = $exhibition_id;
        $data['id_zs'] = $id_zs; // 站上id
        $dataarr = $this->request->param('goodszp');
        $datas = json_decode($dataarr, TRUE);
        if (is_array($datas)) {
            foreach ($datas as $val1) {
                $data['title'] = $val1['product'];   // 新品类别
                $data['is_news'] = $val1['is_news'];   // 是否新品
                $data['index'] = $val1['index'];   // 新品下标，供前端使用
                $data['intro'] = $val1['product_describe_cn']; // 新品介绍 中文
                $data['intro_en'] = $val1['product_describe'];
                if(!empty($val1['product_pic']) && is_array($val1['product_pic'])){
                    $data['pic']=serialize($val1['product_pic']); // @ 如果多图
                }
                if(!empty($val1['category']) && is_array($val1['category'])){
                    $data['category']=serialize($val1['category']); // @ 如果多图
                }
                if(!empty($val1['id'])){
                    $res = $com->edit_com_fxlist($data, ['id' =>$val1['id']], "zsgoodszp");
                }else{
                    $res = $com->insert_com_dan($data, '', 'zsgoodszp');
                }
                if (!$res) {
                    return json(['code' => 0, 'msg' => '操作失败', 'data' => '']);
                }
            }
        }else{
            return json(['code' => 0, 'msg' => '操作失败,未填写完整', 'data' => '']);
        }


        return json(['code' => 1, 'msg' => '操作成功', 'data' => '']);
    }


    public function editOneProduct(){
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('company_id'); // 展商
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }

        $data['title'] = $this->request->param('product');// 新品类别
        $data['is_news'] = $this->request->param('is_news');// 是否新品
        $data['is_news']=$data['is_news']>=0?$data['is_news']:0;
        $data['index'] =$this->request->param('index');// 新品下标，供前端使用
        $data['intro'] = $this->request->param('product_describe_cn');// 新品介绍 英文
        $data['intro_en'] = $this->request->param('product_describe');// 新品介绍 中文
        $data['exhibition_id'] = $exhibition_id;//
        $data['id_zs'] = $id_zs;//
        $pic=$this->request->param('product_pic');
        if(!empty($pic)){
            $picArr=explode(",", $pic);
            if(is_array($picArr) && count($picArr)>0){
                $data['pic']=serialize($picArr); // @ 如果多图
            }
        }
        $data['update_time']=time();
        //            var_dump($picArr);die();
        $id=$this->request->param('id');// 新品类别
        if($id){
            $res =db('zsgoodszp')->where(['id'=>$id])->update($data);
        }else{
            $data['create_time']=time();
            $res =db('zsgoodszp')->insertGetId($data);
        }
        if (!$res) {
            return json(['code' => 0, 'msg' => '操作失败']);
        }
        return json(['code' => 1, 'msg' => '操作成功', 'data' => $id?$id:$res]);
    }
    /**
     * 删除
     */
    public function zp_del()
    {
        $com = new CommonPlus();
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误', 'data' => '']);
        }
        $tabName = 'zsgoodszp';
        $r = db($tabName)->where(['id' => $id])->find();
        if (!$r) {
            return json(['code' => 0, 'msg' => '记录不存在', 'data' => '']);
        }

        $where['id'] = $id;
        $data['is_del'] = 1;
        $r = $com->edit_com_fxlist($data, $where, $tabName);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试', 'data' => '']);
        }
        return json(['code' => 1, 'msg' => '操作成功', 'data' => '']);
    }

    /**
     * 基本信息修改 单个修改 缺表。直接修改
     * @return \think\response\Json|void
     */
    public function zp_edit_lbxs()
    {
        $com = new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        //$create_uid  = $this->admin['id'];
        $data['update_time'] = time();
        // $selfcontent = $this->request->param('selfcontent'); //自定义表单 理论上只有新增 才有 。。让前台隐藏吧


        // com
        $data['title'] = $this->request->param('title');   // 姓名
        $data['title_en'] = $this->request->param('title_en');
        $data['price'] = $this->request->param('price');
        $data['intro'] = $this->request->param('intro');
        $data['intro_en'] = $this->request->param('intro_en');
        $data['pic'] = $this->request->param('pic'); // @ 如果多图
        $data['pic'] = serialize(json_decode($data['pic'], TRUE)); // 序列  


        $where['id'] = $id;
        $tbname = "zsgoodszp";
        //$data2=array('pwd'=>md5($pwd),'account'=>'cccccccccc');
        $where2 = array('id' => $id, 'company_name' => 'test');
        $r = $com->edit_com_fxlist($data, $where, $tbname);

        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功']);
    }

     /**
      *  一个表单样式
     *  数组形式  
     *      * (json_decode(htmlspecialchars_decode($_GPC['datas']),true));die();
     *   // 1.2 版本 有些东西是下拉选择
     *  "[{"id":"16","title":"无缝钢管","pid":"5","guige":"D22","num":"11"}]"  ke ce
     */
    public function zp_edit()
    {
        $com = new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('id_zs'); // 展商
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);

        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }

        // com
        $data['update_time'] = time();
        $data['exhibition_id'] = $exhibition_id;
        $data['id_zs'] = $id_zs; // 站上id
        //
        //$dataarr1 = $this->request->param('pic');
        // $pic = json_decode($dataarr1, TRUE);
        $dataarr = $this->request->param('goodszp');
        $datas = json_decode($dataarr, TRUE);
        if (is_array($datas)) {
            foreach ($datas as $val1) {
                $data['title'] = $val1['product'];   // 新品类别
                $data['is_news'] = $val1['is_news'];   // 是否新品
                $data['index'] = $val1['index'];   // 新品下标，供前端使用
                $data['intro'] = $val1['product_describe_cn']; // 新品介绍 中文
                $data['intro_en'] = $val1['product_describe'];
                if(!empty($val1['product_pic']) && is_array($val1['product_pic'])){
                    $data['pic']=serialize($val1['product_pic']); // @ 如果多图
                }
                if(!empty($val1['category']) && is_array($val1['category'])){
                    $data['category']=serialize($val1['category']); // @ 如果多图
                }
                $res = $com->edit_com_fxlist($data, ['id' =>$val1['id']], "zsgoodszp");
                if (!$res) {
                    return json(['code' => 0, 'msg' => '操作失败', 'data' => '']);
                }
            }
        }else{
            return json(['code' => 0, 'msg' => '操作失败,未填写完整', 'data' => '']);
        }


        return json(['code' => 1, 'msg' => '操作成功', 'data' => '']);
    }


    // 明细
    public function zp_getDetail()
    {
        $com = new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        $where['id'] = $id;
        $tbname = "zsgoodszp";
        $r = $com->sel_com_one('222', $where, $tbname);
        //$r['question_content_sel']=unserialize($r['question_content_sel']);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功', 'data' => $r]);
    }

    // 胸卡相关
    public function zscard_getList(){
        $page = $this->request->param('page');
        $page = max(1,intval($page));
        $pagesize =$this->request->param('pageSize')==""?100:$this->request->param('pageSize');
        $exhibition_id =$this->request->param('exhibition_id');
        $id_zs =$this->request->param('id_zs');
        $status=$this->request->param('status')==''?1:$this->request->param('status');
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);

        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }

        $status = input('status');
        $param=" and is_del=0";

        $keyword =input('keyword');
        if (!empty($keyword)) {
            $param.=" and (title like '%$keyword%' or title_en like '%$keyword%') ";
        }
        if($exhibition_id){   
            $param .= " and exhibition_id=".$exhibition_id;      
        }
        if($id_zs){   
            $param .= " and id_zs=".$id_zs;      
        }

        $sql2="select * ";
        $sql2.=" from crm_zscardattend where 1=1 $param";
        $sql2.=" limit ".($page-1)*$pagesize.",$pagesize";
        //var_dump($sql2);die();
        $list=Db::query($sql2);
        $sql21=" select count(id) as count1 ";
        $sql21.=" from crm_zscardattend where 1=1 $param ";
        $total1=Db::query($sql21);
        $total=$total1[0]['count1']; //st

        return json(['code'=>1,'msg'=>'success','data'=>['list'=>$list,'count'=>$total]]);
    }


        /**
     * 添加
     * @return \think\response\Json|void
     */
    public function zscard_add(){
        $com =new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('id_zs');
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);
        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }
        $data['create_time']=time();
        $data['update_time']=time();
        $data['exhibition_id'] = $exhibition_id;
        $data['id_zs'] = $id_zs; // 站上id
        //$data['name']=$this->request->param('name');   // 姓名
        $data['name_en']=$this->request->param('name_en');
        $data['mobile']=$this->request->param('mobile');
        $data['positions_cn']=$this->request->param('positions_cn'); // 职务
        $data['positions_en']=$this->request->param('positions_en');
        $data['company_name']=$this->request->param('company_name');
        $data['company_name_en']=$this->request->param('company_name_en'); //
        $user_name=$this->request->param('name');
        $user_id=$this->request->param('user_id');
        $nameOrId=$this->getUserId($user_name,$user_id);
        if($nameOrId['code']==0){
            return json(['code'=>0,'msg'=>'身份证：'.$nameOrId['msg']]);
        }
        $data['name']=$user_name;
        $data['user_id']=$user_id;
        $res=$com->insert_com_dan($data, '', 'zscardattend');
        if(!$res){
            return json(['code'=>0,'msg'=>'操作失败','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }

    //验证省份证
    public function userIdOrName(){
        $user_name=$this->request->param('user_name');
        $user_id=$this->request->param('user_id');
        $nameOrId=$this->getUserId($user_name,$user_id);
        return json(['code'=>$nameOrId['code'],'msg'=>'身份证：'.$nameOrId['msg']]);
    }

    public function getUserId($user_name,$user_id){
        $host = "https://eid.shumaidata.com";
        $path = "/eid/check";
        $method = "POST";
        $appcode = "46e8328cca644eb4bbf844f8538bd714";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $appcode);
        $querys = "idcard=".$user_id."&name=".$user_name;
        $bodys = "";
        $url = $host . $path . "?" . $querys;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        //设定返回信息中是否包含响应信息头，启用时会将头文件的信息作为数据流输出，true 表示输出信息头, false表示不输出信息头
        //如果需要将字符串转成json，请将 CURLOPT_HEADER 设置成 false
        curl_setopt($curl, CURLOPT_HEADER, false);
        if (1 == strpos("$".$host, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        $result=curl_exec($curl);
        if($result){
            $result=json_decode($result,true);
            if($result['code']=='0'){
                if($result['result']['res'] == 1){
                    return array('code'=>1,'msg'=>'验证正确');
                }else{
                    return array('code'=>0,'msg'=>$result['result']['description']);
                }
            }else{
                return array('code'=>0,'msg'=>$result['message']);
            }
        }else{
            return array('code'=>0,'msg'=>'请求失败');
        }
    }

       /**
     * 删除
     */
    public function zscard_del(){
        $com = new CommonPlus();
        $id = $this->request->param('id');
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        $tabName='zscardattend';
        $r = db($tabName)->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }         

        $where['id'] = $id;
        $data['is_del'] = 1;
        $r = $com->edit_com_fxlist($data, $where, $tabName);

        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }
        /**
     * 基本信息修改
     * @return \think\response\Json|void
     */
    public function zscard_edit()
    {
        $com =new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        $data['update_time']=time();
        //$data['name']=$this->request->param('name');   // 姓名
        $data['name_en']=$this->request->param('name_en');
        $data['mobile']=$this->request->param('mobile');
        $data['positions_cn']=$this->request->param('positions_cn'); // 职务
        $data['positions_en']=$this->request->param('positions_en');
        $data['company_name']=$this->request->param('company_name');
        $data['company_name_en']=$this->request->param('company_name_en'); //
        $user_name=$this->request->param('name');
        $user_id=$this->request->param('user_id');
        $nameOrId=$this->getUserId($user_name,$user_id);
        if($nameOrId['code']==0){
            return json(['code'=>0,'msg'=>'身份证：'.$nameOrId['msg']]);
        }
        $data['name']=$user_name;
        $data['user_id']=$user_id;
        $where['id'] = $id;
        $tbname="zscardattend";
        $r=$com->edit_com_fxlist($data, $where, $tbname);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功']);
    }
   // 明细
    public function zscard_getDetail()
    {
        $com =new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        $where['id'] = $id;
        $tbname="zscardattend";
        $r=$com->sel_com_one('222', $where, $tbname);
        //$r['question_content_sel']=unserialize($r['question_content_sel']);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功','data'=>$r]);
    }

    // 楣板相关

    public function zs_meiban_getList(){
        $page = $this->request->param('page');
        $page = max(1,intval($page));
        $pagesize =$this->request->param('pageSize')==""?20:$this->request->param('pageSize');
        $exhibition_id =$this->request->param('exhibition_id');
        $id_zs =$this->request->param('id_zs');
        $status=$this->request->param('status')==''?1:$this->request->param('status');
        if(empty($exhibition_id)){
            //return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }

        $status = input('status');
        //back字段 0代表正常 1代表退回数据 2 代表自提 3代表分配
        //status前端传入1代表 全部 2代表 不展示退回数据 3代表 只展示退回数据
        $param=" and is_del=0";
        $keyword =input('keyword');
        if (!empty($keyword)) {
            $param.=" and (title like '%$keyword%' or title_en like '%$keyword%') ";
        }
        if($exhibition_id){   
            $param .= " and exhibition_id=".$exhibition_id;      
        }
        if($id_zs){   
            $param .= " and id_zs=".$id_zs;      
        }



        $sql2="select * ";
        $sql2.=" from crm_zsmeiban where 1=1 $param";
        $sql2.=" limit ".($page-1)*$pagesize.",$pagesize";
        //var_dump($sql2);die();
        $list=Db::query($sql2);
        $sql21=" select count(id) as count1 ";
        $sql21.=" from crm_zsmeiban where 1=1 $param ";
        $total1=Db::query($sql21);
        $total=$total1[0]['count1']; //st

        return json(['code'=>1,'msg'=>'success','data'=>['list'=>$list,'count'=>$total]]);
    }
        /**
     * 添加
     * @return \think\response\Json|void
     */
    public function zs_meiban_add(){
        $com =new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id');
        $id_zs = $this->request->param('id_zs');
        $exhibition = db('exhibition')->where(['is_delete' => 0, 'id' => $exhibition_id])->find();
        if (!$exhibition) {
            return json(['code' => 1, 'msg' => '展会信息错误']);
        }
        $tabName = $this->getTabName($exhibition_id);

        //查询展商信息
        $business = db($tabName)->where(['id' => $id_zs])->find();
        if (!$business) {
            return json(['code' => 1, 'msg' => '展商数据错误']);
        }
        // com
        $data['create_time']=time();
        $data['update_time']=time();
        $data['id_zs']=$id_zs; 
        $data['exhibition_id']=$exhibition_id; 
        $data['title']=$this->request->param('title');   // 中文
        $data['title_en']=$this->request->param('title_en');//英文
        $data['is_havegb']=$this->request->param('is_havegb')==""? 0 : $this->request->param('is_havegb');

        $res=$com->insert_com_dan($data, '', 'zsmeiban');
        if(!$res){
            return json(['code'=>0,'msg'=>'操作失败','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }

    /**
     * 删除
     */
    public function zs_meiban_del(){
        $com =new CommonPlus();
        $id = $this->request->param('id');
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        $tabName='zsmeiban';
        $r = db($tabName)->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $where['id'] = $id;
        $data['is_del']=1;
        $r=$com->edit_com_fxlist($data, $where, $tabName);
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }

        /**
     * 基本信息修改
     * @return \think\response\Json|void
     */
    public function zs_meiban_edit()
    {
        $com =new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        //$create_uid  = $this->admin['id'];
        $data['update_time']=time();

        $data['title']=$this->request->param('title');   // 姓名
        $data['title_en']=$this->request->param('title_en');
        $data['is_havegb']=$this->request->param('is_havegb')==""? 0 : $this->request->param('is_havegb');
        $data['update_time']=time();


        $where['id'] = $id;
        $tbname="zsmeiban";
        $r=$com->edit_com_fxlist($data, $where, $tbname);

        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功']);
    }


    // 明细
    public function zs_meiban_getDetail()
    {
        $com =new CommonPlus();
        // com
        $id = $this->request->param('id');
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        $where['id'] = $id;
        $tbname="zsmeiban";
        $r=$com->sel_com_one('222', $where, $tbname);
        //$r['question_content_sel']=unserialize($r['question_content_sel']);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => '操作成功','data'=>$r]);
    }
    // ed
    //添加身份证正反面
    public function setUserId(){
        $id=$this->request->param('id');//企业库人员id
        $id_positive=$this->request->param('id_positive');//身份证正面
        $id_side=$this->request->param('id_side');//身份证反面
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $info = db($tabName)->where(['person_id'=>$id])->find();
        if(empty($info)){
            return json(['code'=>0,'msg'=>'关键主键id错误']);
        }
        if(empty($id_positive)){
            return json(['code'=>0,'msg'=>'身份证正面错误']);
        }

        if(empty($id_side)){
            return json(['code'=>0,'msg'=>'身份证反面错误']);
        }
        $data['id_positive']=$id_positive;
        $data['id_side']=$id_side;
        $data['status']=4;
        $r = db($tabName)->where(['person_id'=>$id])->update($data);
        if(!$r){
            return json(['code'=>0,'msg'=>'更新失败']);
        }
        //开启验证代码
        if($exhibition['is_open'] == 1){
            $perRes=db($tabName)->where(['person_id'=>$id])->find();
            //判断验证条件
            if($perRes['examine_type'] == 1){//审核通过
                //是否推送结束
                if($perRes['is_push'] == 1){
                    return json(['code'=>1,'msg'=>'操作成功']);
                }else{
                    $rPush=$this->pushCrul($info,$exhibition_id);
                    if($rPush['code'] == 1){
                        $cPer=db($tabName)->where(['id'=>$id])->update(['is_push'=>1]);
                        if(!$cPer){
                            return json(['code'=>1,'msg'=>'保存成功，推送展会失败']);
                        }
                        return json(['code'=>1,'msg'=>'操作成功']);
                    }else{
                        return json(['code'=>1,'msg'=>'保存成功，'.$rPush['msg']]);
                    }
                }
            }else if($perRes['examine_type'] == 0){
                // 进行白黑名单判断
                $blackLis=db('white_black_list')->where(['is_delete'=>0,'type'=>1,'exhibition_id'=>$exhibition_id])->select();
                $blackArr=[];
                foreach ($blackLis as &$vv){
                    if(strpos($vv['title'],$perRes['industrys'])){
                        $blackArr[]=$vv['title'];
                    }
                }
                unset($v,$vv);
                $sms_type=2;
                if(count($blackArr)>0){//在黑名单
                    $sms_type=3;
                    db($tabName)->where(['id'=>$id])->update(['examine_type'=>3]);
                }else{
                    $sms_type=2;
                    $rPushs=$this->pushCrul($info,$exhibition_id);
                    db($tabName)->where(['id'=>$id])->update(['examine_type'=>1,'is_push'=>1]);
                    $this->smsEmail($exhibition,$perRes['id'],1,$exhibition_id);
                }
                $phone_tmp=db('email_sms')->where(['type'=>0,'sms_type'=>$sms_type,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
                if(!$phone_tmp){
                    return json(['code'=>1,'msg'=>'保存成功,短信模板错误']);
                }
                $SmsDemo=new SmsDemo();
                $smsEmil = $SmsDemo->sendBatchSms([$perRes['mobile_person']],[$phone_tmp['sms_autograph']],$phone_tmp['sms_code'],[array('is_cart'=>$perRes['is_cart'],'userName'=>($perRes['name_cn']?$perRes['name_cn']:($perRes['name_en']?$perRes['name_en']:'预登记观众')))]);
                return json(['code'=>1,'msg'=>'操作成功']);
            }
        }else{
            return json(['code'=>1,'msg'=>'操作成功']);
        }
    }
}
